<template>
  <div class="app-container-custom">
    <el-row :gutter="10">
      <el-col :span="5" :xs="24">
        <el-card shadow="never">
          <org-tree ref="orgTree" modelType="'dept','community','floor','unit','room'" @nodeClick="handleNodeClick" @firstNodeClick="handleFirstNodeClick"/>
        </el-card>
      </el-col>
      <el-col :span="19" :xs="24">
        <el-card shadow="never">
          <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="费用类型" prop="projectId">
              <el-input
                v-model="queryParams.projectId"
                placeholder="请输入费用类型"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="收费项目" prop="chargeId">
              <el-input
                v-model="queryParams.chargeId"
                placeholder="请输入收费项目"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="收费标准" prop="normId">
              <el-input
                v-model="queryParams.normId"
                placeholder="请输入收费标准"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>

          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"
                v-hasPermi="['payfee:roomNorm:add']"
              >标准设置</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="success"
                plain
                icon="el-icon-edit"
                size="mini"
                :disabled="single"
                @click="handleUpdate"
                v-hasPermi="['payfee:roomNorm:edit']"
              >修改</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                plain
                icon="el-icon-delete"
                size="mini"
                :disabled="multiple"
                @click="handleDelete"
                v-hasPermi="['payfee:roomNorm:remove']"
              >删除</el-button>
            </el-col>
            <!--<el-col :span="1.5">-->
              <!--<el-button-->
                <!--type="warning"-->
                <!--plain-->
                <!--icon="el-icon-download"-->
                <!--size="mini"-->
            <!--:loading="exportLoading"-->
                <!--@click="handleExport"-->
                <!--v-hasPermi="['payfee:roomNorm:export']"-->
              <!--&gt;导出</el-button>-->
            <!--</el-col>-->
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>

          <el-table v-loading="loading" :data="roomNormList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <!--<el-table-column label="组织机构" align="center" prop="deptName" width="180"/>-->
            <el-table-column label="房屋名称" align="left" prop="roomName" width="200">
              <template slot-scope="scope">
                <!--<span>{{scope.row.communityName}}-{{scope.row.roomName}}</span>-->
                <span>{{scope.row.roomName}}</span>
              </template>
            </el-table-column>
            <el-table-column label="费用类型" align="left" prop="feeCondition.projectType" width="120"/>
            <el-table-column label="收费项目" align="left" prop="feeCondition.chargeName" width="180"/>
            <el-table-column label="收费标准" align="left" prop="feeCondition.normNames" width="180"/>
            <el-table-column label="开始收费时间" align="center" prop="beginChargeTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.beginChargeTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="结束收费时间" align="center" prop="finishChargetime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.finishChargetime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="下一次计费开始时间" align="center" prop="beginChargeTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.nextBeginChargeTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="下一次计费结束时间" align="center" prop="finishChargetime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.nextFinishChargetime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="交讫年月" align="center" prop="deliveryTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.deliveryTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="指定金额" align="center" prop="amountSpecified" width="150"/>
            <el-table-column label="备注" align="center" prop="remark" width="150" show-overflow-tooltip/>
          </el-table>

          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-card>
      </el-col>
    </el-row>
    <room-norm-add  ref="addRef" @cancel="getList"/>

    <room-norm-update ref="udpateRef" @cancel="getList"/>

  </div>
</template>

<script>
import { listRoomNorm, getRoomNorm, delRoomNorm, addRoomNorm, updateRoomNorm, exportRoomNorm } from "@/api/payfee/roomNorm";

import RoomNormAdd from "./add";
import RoomNormUpdate from "./update";

export default {
  name: "RoomNorm",
  components:{RoomNormUpdate, RoomNormAdd},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 房屋收费标准表格数据
      roomNormList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        chargeId: null,
        normId: null,
        nodeId:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectId: [
          { required: true, message: "费用类型不能为空", trigger: "blur" }
        ],
        chargeId: [
          { required: true, message: "收费项目不能为空", trigger: "blur" }
        ],
        normId: [
          { required: true, message: "收费标准不能为空", trigger: "blur" }
        ],
      },
      //当前选中节点
      currentNode:{}
    };
  },
  created() {

  },
  methods: {
    /** 查询房屋收费标准列表 */
    getList() {
      this.loading = true;
      listRoomNorm(this.queryParams).then(response => {
        this.roomNormList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.roomNormId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.addRef.show({currentNode:this.currentNode})
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const roomNormId = row.roomNormId || this.ids
      this.$refs.udpateRef.show(roomNormId)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roomNormIds = row.roomNormId || this.ids;
      this.$confirm('是否确认删除房屋收费标准编号为"' + roomNormIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRoomNorm(roomNormIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有房屋收费标准数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportRoomNorm(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
    handleNodeClick(node){
      this.currentNode = node;
      this.queryParams.nodeId = node.id
      this.getList()
    },
    handleFirstNodeClick(node){
      this.currentNode = node;
      this.queryParams.nodeId = node.id;
      this.getList();
    }
  }
};
</script>
